<?PHP
set_time_limit(0);
  $pdo = new PDO("mysql:host=localhost;dbname=hospital","root","tailiyan88"); 


		
		$sql="select * from diqu";
		$result=$pdo->query($sql);
		foreach($result as $row){

			$jonsm=file_get_contents("https://auth.dxy.cn/pub/assets/hospital/location?location=".$row['code']."&callback=jsonp_08560903564509865");
		
			if(!empty($jonsm))
			{  // 
				$strjson=str_replace("jsonp_08560903564509865(","",$jonsm);
				$strjon=rtrim($strjson,");");
			   $objt=json_decode($strjon,true);
			  
			   foreach($objt as $o)
			   {
				  
				   if(!empty($o) && is_array($o)){
                    $result=$pdo->query("select  count(*)  from hospital where label='".$o['label']."'");
                    $rows = $result->fetch();
                    $rowCount = $rows[0];
                       if ($rowCount>0) { //返回一个字符串
//登录成功
                       } else {
                          $pdo->exec("insert into hospital(`key`,`label`,`dengji`) values('".$o['location']."','".$o['label']."','".$o['grade']."')");
                       }


				   }
				 // die();
			   }
			}
			//sleep(2);
			//
		}
	
	//}
